<?php
 $user_pet = htmlspecialchars($_POST['user_pet']);
 $user_name = htmlspecialchars($_POST['user_name']);
 $user_pwd = htmlspecialchars($_POST['user_pwd']);
 $user_phone = htmlspecialchars($_POST['user_phone']);
 $user_time = htmlspecialchars(date("Y-m-d-H:i:s"));

 if (empty($user_pet) || empty($user_name) || empty($user_pwd) || empty($user_phone)) {
    echo "<script>alert('表单不能有空！');window.location.href='zhuce_index.php';</script>";
 }else{
//htmlspecialchars()：将特殊字符转换为HTML实体，以防止XSS（跨站脚本攻击）。
 require "query_db.php";   // 连接数据库
 // sql 语句
 $sql = "INSERT INTO user_info (user_pet,user_name, user_pwd,user_phone, user_time) VALUES ('$user_pet','$user_name', '$user_pwd','$user_phone', '$user_time')";
 $res = mysqli_query($conn, $sql);  // 执行sql语句

 if (!$res) {  // 判断是否执行成功
     echo "<script>alert('注册失败！');window.location.href='zhuce_index.php';</script>";
 }else{
     echo "<script>alert('注册成功！');window.location.href='index.php';</script>";
 }
 }
 mysqli_close($conn);   // 关闭连接
?>